package com.tju.serviceOrder.service.impl;

import com.tju.Vo.CourseWebVoOrder;
import com.tju.Vo.UcenterMemberVo;
import com.tju.serviceOrder.client.EduClient;
import com.tju.serviceOrder.client.UcenterClient;
import com.tju.serviceOrder.entity.Order;
import com.tju.serviceOrder.mapper.OrderMapper;
import com.tju.serviceOrder.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tju.serviceOrder.utils.OrderNoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.OrderUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author gsc
 * @since 2022-01-18
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    //生成订单需要课程信息和用户信息，因此需要进行远程调用

    @Autowired
    private EduClient eduClient;

    @Autowired
    private UcenterClient ucenterClient;

    @Override
    public String createOrder(String courseId, String memberId) {
        UcenterMemberVo memberInfo = ucenterClient.getUserInfoOrder(memberId);
        CourseWebVoOrder courseInfo = eduClient.getCourseInfoOrder(courseId);
        Order order = new Order();

        order.setOrderNo(OrderNoUtils.getOrderNo());//设置订单号
        order.setMobile(memberInfo.getMobile());
        order.setNickname(memberInfo.getNickname());
        order.setMemberId(memberId);
        order.setCourseCover(courseInfo.getCover());
        order.setCourseId(courseId);
        order.setCourseTitle(courseInfo.getTitle());
        order.setTeacherName(courseInfo.getTeacherName());
        order.setTotalFee(courseInfo.getPrice());
        order.setStatus(0);//支付状态：（ 0：已支付，1：未支付 ）
        order.setPayType(1);//支付类型： 1：微信 ， 2：支付宝
        baseMapper.insert(order);

        return order.getOrderNo();//返回订单号
    }
}
